import { validatePhoneTwo } from './validator'

export default {
  common: (msg: string) => ([{ required: true, message: msg, trigger: 'blur' }]),
  username: [
    { required: true, message: '请输入账号', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
  ],
  checkPassword: (password: number) => ([
    { required: true, message: '请输入确认密码', trigger: 'blur' },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value === '') {
          callback(new Error('请再次输入密码'))
        } else if (value !== password) {
          callback(new Error('两次输入密码不一致'))
        } else {
          callback()
        }
      }, trigger: 'blur',
    },
  ]),
  mobile: [
    { required: true, message: '请输入手机号', trigger: 'blur' },
    { validator: validatePhoneTwo, trigger: 'blur' },
  ],
  email: [
    { required: true, message: '请输入邮箱地址', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] },
  ],
}
